<?php

require ROOT_PATH.'/Helper/admin_base_abstract.php';

abstract class admin_abstract extends admin_base_abstract
{
    private static $action_list = array(

        // 'Manage Content' => array(
        //     'Storefronts' => 'store_front',
        //     'Assets' => 'asset_manage',
        //     'My Assets' => 'my_asset'
        // ),

        'English' => array(
            'User Group Permissions' => 'user_group',
            // 'Tags and Categories' => 'tag_manage',
            'Manage Admistrative Users' => 'admin_manage',
            // 'Manage Companies' => 'company_manage',
            // 'Asset Status' => 'unpublish',
            // 'Review Pending Assets' => 'verifyasset',
            // 'Manage Marquees' => 'marquees_manage',
            // 'Registered Users' => 'registered_users',
            // 'Manage Comments' => 'comment_manage',
            // 'Analytic Setting' => 'setting',
            'My Account' => 'my_account',
            'Business Input' => 'business_input',
            'Business Input option' => 'asset_manage.html?cate_id=4&lang=0',
            'Business Input info' => 'asset_manage/edit.html?id=23',
            'News' => 'asset_manage.html?cate_id=1&lang=0',
            'About' => 'asset_manage.html?cate_id=2&lang=0',
            'Banner' => 'asset_manage.html?cate_id=3&lang=0',
            'index marquees'=>'marquees_manage.html?id=0',
        ),
        '中文' => array(
            'Business Input提示' => 'asset_manage/edit.html?id=24',
            '联系我们信息设置' => 'asset_manage.html?cate_id=4&lang=1',
            '新闻' => 'asset_manage.html?cate_id=1&lang=1',
            '关于我们' => 'asset_manage.html?cate_id=2&lang=1',
            '广告' => 'asset_manage.html?cate_id=3&lang=1',
            '首页广告'=>'marquees_manage.html?id=1',
            
            
        ),
    );

    function __construct($controller)
    {
        parent::__construct($controller);
        if (empty($_SESSION['admin_user'])) {
            $this->redirect('admin/login.html');
        }
        $this->info = $_SESSION['admin_user'];
        $this->view->assign('controller', $controller);

        $admin_group = $this->get_admin_group();
        
        $this->info['user_group'] = $admin_group[$this->info['user_group']];
        $this->info['tags'] = array_filter(explode('|', $this->info['tags']));

        if ($controller !== 'index') {
            if (!in_array($controller, $this->info['user_group']['modules'])) {
                // show msg
                // no permision
                // $this->msg('no permission');
            }
        }


        $this->view->assign('action_list', self::$action_list);

        $menu = self::$action_list;
        foreach ($menu as $key => $val) {
            foreach ($val as $k => $v) {
                if (!in_array($v, $this->info['user_group']['modules'])) {
                    unset($menu[$key][$k]);
                }
            }
        }

        $this->view->assign('menu', array_filter($menu));
    }

    function get_admin_group()
    {
        static $mdata = null;
        if ($mdata !== null) {
            return $mdata;
        }

        if (!$data = $this->cache->get('admin_group')) {
            $t = _model('user_group')->getList('ORDER BY id');
            $data = array();
            foreach ($t as $key => $val) {
                $val['modules'] = array_filter(explode('|', $val['modules']));
                $data[$val['id']] = $val;
            }
            $this->cache->set('admin_group', $data);
        }
        
        $mdata = $data;

        return $data;
    }
}

?>